package com.glodon.paas.account.web.util;

import java.util.Map;

import com.glodon.paas.account.api.bean.Address;
import com.glodon.paas.account.api.bean.Company;
import com.glodon.paas.account.api.bean.Contact;
import com.glodon.paas.account.api.bean.User;
import com.glodon.paas.util.PropertyUtil;

public class UserInfoMappingUtil {

	private static Map<String, String> infoMap = PropertyUtil.convertFileToMap("userInfoMapping");

	public static String getValue(String key) {
		if (infoMap.containsKey(key)) {
			return (String) infoMap.get(key);
		} else {
			return key;
		}
	}
	
	public static Address translate(Address addr) {
		if(addr!=null){
			Address dto = new Address();
			dto.setAddress(addr.getAddress());
			dto.setZipcode(addr.getZipcode());
			dto.setCity(getValue(addr.getCity()));
			dto.setScity(getValue(addr.getScity()));
			return dto;
		}
		return null;
	}
	
	public static Company translate(Company comp) {
		if(comp!=null){
			Company dto = new Company();
			dto.setAddress(translate(comp.getAddress()));
			dto.setCompany(comp.getCompany());
			dto.setIndustry(comp.getIndustry());
			dto.setPosition(comp.getPosition());
			comp.setJobCategory(getValue(comp.getJobCategory()));
			return dto;
		}
		return null;
	}
	
	public static Contact translate(Contact contact) {
		if(contact!=null){
			Contact dto = new Contact();
			dto.setAddress(translate(contact.getAddress()));
			dto.setPhone(contact.getPhone());
			dto.setTel(contact.getTel());
			return dto;
		}
		return null;
	}
	
	public static User fillUserPropertyText(User user){
		if(user!=null){
			user.setAddress(translate(user.getAddress()));
			user.setCompany(translate(user.getCompany()));
			user.setContact(translate(user.getContact()));
			return user;
		}
        return null;
	}
}
